import { defineEventHandler, getRouterParam } from 'h3';

export default defineEventHandler(async (event) => {
  const resourceId = getRouterParam(event, 'resourceId');

  // 模拟状态变更历史数据
  const statusHistory = [
    {
      id: '1',
      resourceId,
      statusType: 'LIFECYCLE',
      oldStatus: 'DRAFT',
      newStatus: 'ACTIVE',
      reason: '资源初始化完成',
      operator: 'admin',
      timestamp: new Date(Date.now() - 86400000).toISOString(), // 1天前
    },
    {
      id: '2',
      resourceId,
      statusType: 'AVAILABILITY',
      oldStatus: 'UNAVAILABLE',
      newStatus: 'AVAILABLE',
      reason: '系统维护完成',
      operator: 'system',
      timestamp: new Date(Date.now() - 3600000).toISOString(), // 1小时前
    },
    {
      id: '3',
      resourceId,
      statusType: 'VERSION',
      oldStatus: 'DRAFT',
      newStatus: 'ACTIVE',
      reason: '版本发布',
      operator: 'admin',
      timestamp: new Date(Date.now() - 1800000).toISOString(), // 30分钟前
    },
  ];

  return {
    code: 0,
    data: statusHistory,
    msg: '获取资源状态历史成功',
  };
});
